using B.S.NewMedical.Api.Read.Application.Command.MobileService.Guide;
using B.S.NewMedical.Api.Read.DTOS.Guide;
using B.S.NewMedical.ErrorCode;
using MediatR;
using Microsoft.AspNetCore.Mvc;
using System.Collections.Generic;
using System.Threading.Tasks;

namespace B.S.NewMedical.Api.Read.Controllers
{
    [Route("api/[controller]")]
    [ApiController]
    public class GuideController : ControllerBase
    {
        private readonly IMediator _mediator;

        public GuideController(IMediator mediator)
        {
            _mediator = mediator;
        }

        /// <summary>
        /// 获取就医指南分类列表
        /// </summary>
        /// <returns>就医指南分类列表</returns>
        [HttpGet("categories")]
        public async Task<ApiResult<List<GuideCategoryDto>>> GetCategories()
        {
            return await _mediator.Send(new GetGuideCategoriesCommand());
        }

        /// <summary>
        /// 获取就医指南文章列表
        /// </summary>
        /// <param name="categoryId">分类ID，可选</param>
        /// <returns>就医指南文章列表</returns>
        [HttpGet("articles")]
        public async Task<ApiResult<List<GuideArticleDto>>> GetArticles(
            [FromQuery] int? categoryId = null)
        {
            return await _mediator.Send(new GetGuideArticlesCommand(categoryId));
        }

        /// <summary>
        /// 获取就医指南文章详情
        /// </summary>
        /// <param name="articleId">文章ID</param>
        /// <param name="userId">用户ID，可选，用于获取互动状态</param>
        /// <returns>就医指南文章详情</returns>
        [HttpGet("detail/{articleId}")]
        public async Task<ApiResult<GuideDetailDto>> GetDetail(
            int articleId, 
            [FromQuery] int? userId = null)
        {
            return await _mediator.Send(new GetGuideDetailCommand(articleId, userId));
        }
    }
} 